import request from '@/utils/request'

export function getAllClazz() {
  return request({
    url: '/clazz/',
    method: 'get'
  })
}

export function getClazzOptions() {
  return getAllClazz().then((rawData)=>{
    for(let campus of rawData.data){
      campus.value = campus.id.toString();
      campus.label = campus.name
      for(let major of campus.majors) {
        major.value = major.id.toString();
        major.label = major.name;
        for(let clazz of major.clazzList) {
          clazz.value = clazz.id.toString()
          clazz.label = clazz.name.toString();
        }
        major.children = major.clazzList;
      }
      campus.children = campus.majors;
    }
    return rawData.data;
  })
}

export default {
  getAllClazz,
  getClazzOptions
}
